package com.pan.server.controller;

import com.github.pagehelper.PageInfo;
import com.pan.common.result.Result;
import com.pan.pojo.dto.BookDTO;
import com.pan.pojo.dto.PageDTO;
import com.pan.pojo.vo.BookVO;
import com.pan.server.service.BooksService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/books")
@Slf4j
@Api(tags = "书籍控制器")
@RestController
@CrossOrigin("http://localhost:7070")
public class BooksController {

    @Autowired
    private BooksService booksService;

    /**
     * 书籍查询
     * @param bookPageDTO
     * @return
     */
    @PostMapping(value = "/queryBooks")
    @ApiOperation("书籍查询")
    public Result<PageInfo<BookVO>> queryBooks(@RequestBody PageDTO bookPageDTO){
        log.info("书籍查询...");

        PageInfo<BookVO> pageInfo = booksService.queryBooks(bookPageDTO.getPageNum(), bookPageDTO.getPageSize());

        return Result.success(pageInfo);
    }

    @PostMapping(value = "/searchBooks")
    @ApiOperation("书籍搜索")
    public Result<PageInfo<BookVO>> searchBooks(@RequestBody BookDTO bookDTO){
        log.info("书籍搜索...");

        PageInfo<BookVO> pageInfo = booksService.searchBooks(bookDTO, bookDTO.getPageNum(), bookDTO.getPageSize());

        return Result.success(pageInfo);
    }

}